<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/9/15
  Time: 12:31
  To change this template use File | Settings | File Templates.
  公共分页条【工具】
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<div align="center">
    <a href="${requestScope.page.url}&pageNo=1">首页</a>
    <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo-1==0?requestScope.page.pageTotal:requestScope.page.pageNo-1}">上一页</a>

    【
    <%-- 显示的页码数量为5个，一般情况下当前页码位于中央，特殊情况可以位于两边--%>
    <c:choose>
        <%--        情况1、如果总页码小于等于5--%>
        <c:when test="${requestScope.page.pageTotal<=5}">
            <c:set var="begin" value="1"></c:set>
            <c:set var="end" value="${requestScope.page.pageTotal}"></c:set>
        </c:when>
        <%--        情况2、如果总页码大于5--%>
        <c:otherwise>
            <c:if test="${requestScope.page.pageNo<=3}">
                <c:set var="begin" value="1"></c:set>
                <c:set var="end" value="5"></c:set>
                <c:set var="right" value="..."></c:set>
            </c:if>
            <c:if test="${requestScope.page.pageNo>=requestScope.page.pageTotal-2}">
                <c:set var="left" value="..."></c:set>
                <c:set var="begin" value="${requestScope.page.pageTotal-4}"></c:set>
                <c:set var="end" value="${requestScope.page.pageTotal}"></c:set>
            </c:if>
            <c:if test="${requestScope.page.pageNo>3&&requestScope.page.pageNo<requestScope.page.pageTotal-2}">
                <c:set var="left" value="..."></c:set>
                <c:set var="begin" value="${requestScope.page.pageNo-2}"></c:set>
                <c:set var="end" value="${requestScope.page.pageNo+2}"></c:set>
                <c:set var="right" value="..."></c:set>
            </c:if>
        </c:otherwise>
    </c:choose>
    <%--begin为要显示的起始页码值，end为要显示的结束页码值，left为左边的省略号(特殊情况显示)，right为右边的省略号(特殊情况显示)--%>
    ${empty left?" ":left}
    <c:forEach begin="${begin}" end="${end}" var="i">
        <a href="${requestScope.page.url}&pageNo=${i}">
                ${i==requestScope.page.pageNo?[i]:i}
        </a>
        <%=" "%>
    </c:forEach>
    ${empty right?" ":right}
    】

    <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageNo+1>requestScope.page.pageTotal?1:requestScope.page.pageNo+1}">下一页</a>
    <a href="${requestScope.page.url}&pageNo=${requestScope.page.pageTotal}">尾页</a>
    共${requestScope.page.pageTotal}页，
    ${requestScope.page.pageTotalCount}条记录，
    到第<input type="text" id="pageBtn" style="width: 5%">页
    <input type="button" value="确定" id="searchPageBtn">
    <br>
    <script type="text/javascript">
        $(function () {
            //给按钮绑定“跳到指定页面”
            $("#searchPageBtn").click(function () {
                var pageNo = $("#pageBtn").val();
                //javaScript语言中提供了一个Location地址栏对象
                //它有一个属性href,它可以获取浏览器地址栏中的地址
                //属性href可读可写
                // alert("location.href");
                location.href="${pageScope.basePath}${requestScope.page.url}&pageNo="+pageNo;
            });
        });
    </script>
</div>
